﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HomeWorks
{

    


    class Program
    {

        static StringBuilder InputDatafromConsole()
        {

            Console.WriteLine("Enter your code here:");
            StringBuilder data = new StringBuilder();
           do
            {
                string InputData = System.Console.ReadLine();
                if (InputData == null) break;
                data.Append(InputData);
                data.Append("\n");
            } while (true);

              return data;
             
            }

        static StringBuilder RemoveDoubleSlash(StringBuilder data)
        {
            string DoubleSlash = "//";
            string NewLine = "\n";
            string ExcludeQuota = "\"";
            int index=0;
            int indexquota=0;
            
            //locate in data doubleslash
            do
            {
                int start = data.ToString().IndexOf(DoubleSlash,index);
                if (start == -1) break;
                int startquota = data.ToString().IndexOf(ExcludeQuota, indexquota);
                int endquota= data.ToString().IndexOf(ExcludeQuota, startquota +1);
                int end = data.ToString().IndexOf(NewLine ,start +1);
               // if (end < endquota) indexquota = startquota + 1;
                if (end > 0)
                {
                    if ((start > startquota) && (start > endquota))
                    {
                        data.Remove(start, end - start);
                    }
                }
                index=start+1;
                indexquota = endquota  + 1;
            } while (true);

               

            return data;
        }






        static StringBuilder RemoveNewLine(StringBuilder data)
        {
            string NewLine = "\n";
            int start, index;
            //Remove NewLine in begin of data
            do
            {
                start = data.ToString().IndexOf(NewLine);
                if (start == 0) data.Remove(0, 1);
            }
            while (start == 0);
             index=1;
             do
             {
                 start = data.ToString().IndexOf(NewLine, index);
                 if (start == -1) break;
                 if (data.ToString().IndexOf(NewLine, index + 1) == start + 1)
                 {
                     data.Remove(index, 1);
                 }
                 else
                 {
                     index++;
                 }
                                        
             } while (index<data.Length); 
            
            return data;
        }





        static void Main(string[] args)
        {


           // string InputText ="\n"+"\n"+ "first line"+"\n"+"second \n line"+"\n"+"//comentar"+"\n"+"\n"+"End Line";
            //StringBuilder InputTextCorrect= new StringBuilder (InputText );
            StringBuilder InputTextCorrect = InputDatafromConsole();
            Console.WriteLine("Your code is:");
            Console.WriteLine(InputTextCorrect);
            Console.WriteLine("Correction:");

            Console.WriteLine(RemoveDoubleSlash(InputTextCorrect));



            //Pause  
            Console.ReadKey();
        }
    }
}
